/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.inventory.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.inventory.entity.ZlmtHostsCabinet;
import com.thinkgem.jeesite.modules.inventory.service.ZlmtHostsCabinetService;

/**
 * 资产管理Controller
 * @author johnKee
 * @version 2016-07-20
 */
@Controller
@RequestMapping(value = "${adminPath}/inventory/zlmtHostsCabinet")
public class ZlmtHostsCabinetController extends BaseController {

	@Autowired
	private ZlmtHostsCabinetService zlmtHostsCabinetService;
	
	@ModelAttribute
	public ZlmtHostsCabinet get(@RequestParam(required=false) String id) {
		ZlmtHostsCabinet entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = zlmtHostsCabinetService.get(id);
		}
		if (entity == null){
			entity = new ZlmtHostsCabinet();
		}
		return entity;
	}
	
	@RequiresPermissions("inventory:zlmtHostsCabinet:view")
	@RequestMapping(value = {"list", ""})
	public String list(ZlmtHostsCabinet zlmtHostsCabinet, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ZlmtHostsCabinet> page = zlmtHostsCabinetService.findPage(new Page<ZlmtHostsCabinet>(request, response), zlmtHostsCabinet); 
		model.addAttribute("page", page);
		return "modules/inventory/zlmtHostsCabinetList";
	}

	@RequiresPermissions("inventory:zlmtHostsCabinet:view")
	@RequestMapping(value = "form")
	public String form(ZlmtHostsCabinet zlmtHostsCabinet, Model model) {
		model.addAttribute("zlmtHostsCabinet", zlmtHostsCabinet);
		return "modules/inventory/zlmtHostsCabinetForm";
	}

	@RequiresPermissions("inventory:zlmtHostsCabinet:edit")
	@RequestMapping(value = "save")
	public String save(ZlmtHostsCabinet zlmtHostsCabinet, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, zlmtHostsCabinet)){
			return form(zlmtHostsCabinet, model);
		}
		zlmtHostsCabinetService.save(zlmtHostsCabinet);
		addMessage(redirectAttributes, "保存资产信息成功");
		return "redirect:"+Global.getAdminPath()+"/inventory/zlmtHostsCabinet/?repage";
	}
	
	@RequiresPermissions("inventory:zlmtHostsCabinet:edit")
	@RequestMapping(value = "delete")
	public String delete(ZlmtHostsCabinet zlmtHostsCabinet, RedirectAttributes redirectAttributes) {
		zlmtHostsCabinetService.delete(zlmtHostsCabinet);
		addMessage(redirectAttributes, "删除资产信息成功");
		return "redirect:"+Global.getAdminPath()+"/inventory/zlmtHostsCabinet/?repage";
	}

}